package com.meta.platform.oplog.common;


import com.meta.framework.common.utils.SecurityUtils;
import com.meta.platform.oplog.entity.OperateLog;
import com.meta.platform.oplog.repository.OperateLogRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author shijun
 */
@Component
public class OperateLogHandler {

    private static final Logger logger = LoggerFactory.getLogger(OperateLogHandler.class);

    @Resource
    private OperateLogRepository operateLogRepository;

    // 操作日志内容常量
//    public static final  String CREATE_SIGNER_OPERATE_CONTENT = "新增签署账户";
//    public static final  String CERTIFICATE_SIGNER_OPERATE_CONTENT = "完成实名认证";
//    public static final  String CREATE_ACCOUNT_OPERATE_CONTENT = "创建签署账户";
//    public static final  String UPDATE_ACCOUNT_OPERATE_CONTENT = "更新签署账户";
//    public static final  String CANCEL_ACCOUNT_OPERATE_CONTENT = "注销签署账户";
//    public static final  String UPDATE_SEALER_OPERATE_CONTENT = "更新印章类型/颜色";

    /**
     * 添加操作日志
     *
     * @Author shijun
     * @Date 2020-06-29
     */
    public void addLog(String businessTypeCode, String businessKey, Integer opTypeCode, String content) {
        try {
            OperateLog record = new OperateLog();
            record.setClient("CRM");
            record.setBusinessKey(businessKey);
            record.setBusinessType(businessTypeCode);
            record.setOperateType(opTypeCode);
            record.setContent(content);
            record.setCreateUserId(SecurityUtils.getUserId());
            record.setUpdateUserId(SecurityUtils.getUserId());
            record.setDelFlag(0);
            operateLogRepository.insertOperateLog(record);
        } catch (Exception e) {
            logger.error("新增操作日志发生异常：", e);
        }
    }

}
